package cl.utalca.DB;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBManager {

	public static Connection getConnection() throws SQLException, NamingException{
	  Context ctx = null;
	    try {
	      Properties prop = new Properties();
	      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
	          "com.sun.jndi.fscontext.RefFSContextFactory");
	      prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
	      ctx = new InitialContext(prop);
	    } catch (NamingException ne) {
	      System.err.println(ne.getMessage());
	    }

	    DataSource ds = (DataSource) ctx.lookup("joe");
	    Connection conn = ds.getConnection();
	    
	    return conn;
	}
}
